Skip to content

test(cli): pin the three-probe restart acceptance for an API-created package - #20069

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-17676-package-restart-acceptance
Sep 25, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-17676-package-restart-acceptance

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Part of #17676 — ruling A′ item 5, the acceptance. #17676 remains open: at this head probe 2 disagrees after a restart, and its cause is in packages/runtime (the domain:cli lane), outside this card's file surface.

Clause-②: no

What this adds

  • packages/cli/test/package-restart-acceptance.integration.test.ts. This is a declared cross-lane, test-only edit: one new test file under packages/cli, and no source change in packages/cli or packages/rest.
  • It boots os serve --dev twice on ONE SQLite file. The host app declares neither marketplace nor package-registry (the examples/app-crm shape), so this is the stock composition.
  • On the first boot it runs the card's repro chain: POST /api/v1/packages with the body Studio's create dialog sends, then PUT /api/v1/meta/object/leave_request?mode=draft&package=com.example.leave, then POST /api/v1/packages/com.example.leave/publish-drafts. It reads the three probes, stops, boots again, and reads them again.
  • Harness: it reuses the shared spawn helpers in test/helpers/serve-process.ts (CLI, TSX, childEnv, probeThroughChild, the port errors). It also follows the long-lived-boot pattern of serve-package-registry-always-on.e2e.test.ts. That file's bootServe / stop are file-local, so they are repeated here rather than lifted: lifting them would edit a domain:cli file outside this card's surface.

The three probes, measured

probe route before restart after restart
1 · Studio writable list GET /api/v1/packages, rows whose scope is not system/cloud and whose writable is true com.example.leave listed listed
2 · data GET /api/v1/data/leave_request 200 404 OBJECT_NOT_FOUND — Object 'leave_request' is not registered
3 · published GET /api/v1/meta/object/leave_request/published 200 200

Where probe 1's route comes from. objectui at the pinned .objectui-sha 62597c58:

  • packages/app-shell/src/views/studio-design/BuilderLanding.tsx renders the heading engine.studio.landing.mineHeading ("My packages (writable)", upper-cased by CSS) and the empty state engine.studio.landing.noneWritable ("No writable packages yet — create one to start.").
  • It lists fetchPackages() filtered to writable.
  • studio-design/packages-io.ts fetchPackages() is ONE read, fetch('/api/v1/packages'), with no query parameters. parsePackages drops scope: system | cloud rows and reads the row's top-level writable.
  • On the server, GET /packages is packages/runtime/src/domains/packages.ts: registry.getAllPackages(), then withWritableVerdict.
  • The pin's studioWritableIds is that reader. It leaves out the client's fallback for servers that send no writable.

Why probe 2 disagrees: root cause, measured

  1. For a config app, the stock serve composition is createStandaloneStack (packages/runtime/src/standalone-stack.ts). It builds new ObjectQLPlugin({ environmentId, runPlatformMigrations }) with environmentId defaulting to 'env_local' and no hydrateMetadataFromDb.
  2. ObjectQLPlugin.start() hydrates sys_metadata only when environmentId === undefined || hydrateMetadataFromDb. Otherwise it logs Project kernel — skipping sys_metadata hydration (metadata sourced from artifact). A debug-level reboot on the same database file prints exactly that line.
  3. The published row sits in sys_metadata with state = active, organization_id NULL and package_id = com.example.leave. That is exactly what loadMetaFromDb selects, but the row is never read. So the object is never re-registered and the data route answers 404, while the published read answers 200 straight off the stored row. Reading GET /api/v1/meta/object/leave_request and the object list on the live second boot does not change the 404.
  4. Diagnostic, never committed. I added only hydrateMetadataFromDb: true to that constructor call and rebuilt @objectstack/runtime. On the same database file, probe 2 then answers 200 after the restart. Through this pin (leg B below), the other four assertions pass and the it.fails goes red. So all three probes agree.
  5. Not fixed here. packages/runtime is the domain:cli lane, outside this card's file surface. The skip line's own words ("metadata sourced from artifact") are false on this composition, where runtime-authored metadata lives in sys_metadata. That is part of the same defect, not a second one.

How the agreement is pinned

Tier

  • The file name carries no nightly tier (scripts/nightly-tiers.mjs). It spawns the CLI, so vitest-tiers.ts places it in the integration project, and it runs in the per-PR and merge-queue Test Core.
  • Measured with vitest list --filesOnly: --project integration lists it 1 time and --project unit 0 times. Under OS_TEST_TIERS=nightly it is listed 0 times; the control, serve-package-registry-always-on.e2e.test.ts, is listed 1 time.
  • Cost: 22–23 s held under the verify lock per run (two boots).
  • Why not nightly: the change that fixes probe 2 lives in a dependency of this suite. Test Core therefore runs this file on that pull request, so the it.fails flips there rather than on a nightly after the change lands.

Before / after (every run at 8af659d715, every mutation through scripts/ablation-replace.mjs, each restore proven by blob equality with HEAD and an empty git diff HEAD)

run mutation result
head none 4 passed, 1 expected fail
reason it.fails( → it( in this file 1 failed: GET /data/leave_request after a restart: {"error":"Object 'leave_request' is not registered","code":"OBJECT_NOT_FOUND","object":"leave_request"} (code OBJECT_NOT_FOUND): expected 404 to be 200; 4 passed
ablation A the 'package-registry' key of Serve.CAPABILITY_PROVIDERS renamed, so the key is absent. bin/run-dev.js runs serve.ts from src through tsx, so there is no dist hop 1 failed (probe 1 after the restart), 3 passed, 1 expected fail. The failure transcript's plugin row carries 0 PackageServicePlugin
leg B hydrateMetadataFromDb: true in createStandaloneStack, through dist: @objectstack/runtime rebuilt, ablation-dist-preflight finds the marker in index.js and index.cjs 4 passed; the it.fails is red with Expect test to fail

For the restore, @objectstack/runtime was rebuilt from pristine source and ablation-dist-preflight --absent exited 0 (the marker is absent from all 6 built files). It was checked again after the full package build below.

Tests and gates (at 8af659d715)

  • The pin: pnpm --filter @objectstack/cli exec vitest run --project integration --maxWorkers=2 test/package-restart-acceptance.integration.test.ts gives 1 file: 4 passed, 1 expected fail.
  • Unit project: pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2 gives 224 files and 3158 tests passed. That includes the tier partition pin test/vitest-tiers-partition.test.ts.
  • Typecheck: pnpm --filter @objectstack/cli typecheck exits 0. The check:test-typecheck ledger is unchanged (3 files / 28 errors / 6 signatures). The new file is in the tsconfig.test.json program (--listFiles: 1).
  • Rest of the integration project: declared to CI. A new standalone test file shares no state with the other 51 files.
  • ESLint, narrowed: eslint --no-inline-config --format json on the new file reports 1 file, 0 errors, 0 warnings. The population is eslint's own --print-config for that file. Invariance: the config enables no type-aware linting (eslint.config.mjs says so, and the resolved parserOptions carry no project), so adding one file cannot change any other file's verdict.
  • Derived gates: node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack from the real diff gives 48 commands, and all 48 finish at exit 0. Two were NOT MEASURED on the first pass: check:dual-build-cjs-loads (exit 3, PREREQUISITE NOT MET, 12 packages without dist) and check:type-check-debt (exit 124, my 280 s per-command timeout). Both exit 0 after a full package build (turbo, 72/72). --ran reports 48 derived, 48 run, 0 NOT-MEASURED, 0 UNRUN.
  • Citations: node scripts/check-issue-citations.mjs --base 2274894cc exits 0 but reads 0 files. packages/**/*.test.ts is a declared deferred surface of that gate, so its green says nothing about this diff. The only number this file cites is A writable package created via POST /api/v1/packages is registered in memory only — it does not survive a restart, and leaves its published metadata orphaned #17676.

Changeset

None; skip-changeset applies. @objectstack/cli ships files: ["dist", "README.md", "CHANGELOG.md"] and builds from src. After pnpm --filter @objectstack/cli build, a grep of those paths for studioWritableIds / package-restart-acceptance finds 0 files. The control, PackageServicePlugin, is found in 1 dist file.

Acceptance notes

  • H1 holds at this head. The stock boot's banner lists PackageServicePlugin once, and the install logs no in-memory-only line.
  • Protocol warning on every restart. Each restart warns package 'com.example.leave' declares no engines.protocol range; rehydrating without a compatibility check (ADR-0087) for a package created with Studio's create-dialog body, which sends no engines. This is an observation and is not filed.
  • Harness duplication. bootServe / stop now exist in two packages/cli/test files (see above). Lifting them into test/helpers/serve-process.ts is the domain:cli seat's call.
  • origin/main moved. It moved 5 commits since this branch's base 2274894cc. The only overlap with the packages this pin exercises is packages/objectql/src/validation/rule-validator.ts (validation-rule traversal), which is not the hydration seam. I did not merge main in; the merge queue rebuilds on the current main.

Generated by Claude Code

…package

Boots `os serve --dev` twice on one SQLite file, runs the create-package ->
draft -> publish-drafts chain, and reads Studio's writable list, the data
route and the published-object route before and after the restart.

Claude-Session: https://claude.ai/code/session_01Bvd69VPa6puiNzzPUroDBx
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

Nothing in this diff resolved to a documentable surface (no symbol, route or SDK anchor derived from 0 changed package(s)), so this run has no opinion about the docs.

What this run could not see

Coarse fallback — 0 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json b76aad5f6fac71cbbcd4ea6bfdf21a59e2fd4d56 → packageMentionDocs.

@github-actions github-actions Bot added the tests label Sep 25, 2026
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Sep 25, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review September 25, 2026 01:40
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Sep 25, 2026
Merged via the queue into main with commit 7f1de2e Sep 25, 2026
40 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-17676-package-restart-acceptance branch September 25, 2026 02:13
akarma-synetal pushed a commit to akarma-synetal/framework that referenced this pull request Sep 28, 2026
…ta back into the registry (objectstack-ai#20100)

Fixes objectstack-ai#20071
Clause-②: no

## What was wrong

`createStandaloneStack` (`packages/runtime/src/standalone-stack.ts`) is
the composition behind `os dev` / `os serve` / `os start`. It stamps
`environmentId: 'env_local'` (or whatever `OS_ENVIRONMENT_ID` names),
and it built `new ObjectQLPlugin({ environmentId, runPlatformMigrations
})` with no `hydrateMetadataFromDb`.

`ObjectQLPlugin.start()` hydrates only `if (this.environmentId ===
undefined || this.hydrateMetadataFromDb)`
(`packages/objectql/src/plugin.ts:767`). So every self-hosted boot:
- skipped reading `sys_metadata`;
- logged "Project kernel — skipping sys_metadata hydration (metadata
sourced from artifact)".

An object published at runtime then answered `404 OBJECT_NOT_FOUND` on
the data API after a restart, while its row was still stored. This is
the same deduction that the `[objectstack-ai#9380]` note in the same file records for
`runPlatformMigrations`.

## The fix: a declaration, not a deduction

- `createStandaloneStack` constructs `new ObjectQLPlugin({
environmentId, runPlatformMigrations: cfg.runPlatformMigrations ?? true,
hydrateMetadataFromDb: true })`. The `[objectstack-ai#20071]` comment at that line
carries the caution check below.
- `StandaloneStackConfigSchema` and the published
`StandaloneStackConfig` type are unchanged.
- The only other edit in the file: objectstack-ai#9380's docblock pointer "line ~567
below" now reads "`createStandaloneStack` below".
- `packages/objectql/**` and `packages/spec/**` are untouched.

Opt-out: none. No caller of `createStandaloneStack` can make either
clause of the caution false; adding a key later is its own card,
declared `Clause-②: yes (widening)`.

## The plugin's caution, clause by clause

The caution is on `ObjectQLPluginOptions.hydrateMetadataFromDb`
(`plugin.ts:174-177`): "Set this ONLY when the kernel's registry is
per-instance isolated AND `sys_metadata` lives on the kernel's own local
driver (no control-plane proxy)". Both clauses are properties of
`createStandaloneStack` itself, not of its caller.

1. **Per-instance isolated registry: holds.**
- The function constructs a fresh `ObjectQLPlugin` and passes no `ql`,
so `init()` runs `this.ql = new ObjectQL(hostCtx)` (`plugin.ts:397`).
- Each `ObjectQL` owns its registry: `private _registry: SchemaRegistry
= new SchemaRegistry();` (`engine.ts:3061`, whose comment says "Each
engine now owns its registry so kernels are fully isolated").
   - `SchemaRegistry` (`registry.ts:1819`) has no static members.
2. **`sys_metadata` on the kernel's own local driver: holds.**
- `SysMetadataObject`
(`packages/metadata-core/src/objects/sys-metadata.object.ts:17`)
declares no `datasource`, so it routes to the default driver.
- The function composes exactly one datasource,
`DefaultDatasourcePlugin` as `default` (ADR-0062 D1: "every unbound
object routes to it").
- Every `databaseDriver` kind the function dispatches (`memory`,
`sqlite`, `sqlite-wasm`, `postgres`, `mysql`, `mongodb`, `turso`) is a
direct driver, never a control-plane proxy.
- The hydration read is `this.engine.find('sys_metadata', { where: {
state: 'active', organization_id: null } })` (`loadMetaFromDb` in
`packages/metadata-protocol/src/protocol.ts`), through that same engine.

## Stop valve: every caller of `createStandaloneStack`, measured

`git grep createStandaloneStack` at `a4ca69a9` finds three production
callers, plus tests and fixtures:

| caller | what it is | `sys_metadata` | hydrates after this PR |
|:--|:--|:--|:--|
| `packages/cli/src/commands/serve.ts:2740` | `os serve` / `os dev` /
`os start` with a config | the stack's own `default` driver | yes
(declared) |
| `packages/runtime/src/default-host.ts:163` (`createDefaultHostConfig`)
| artifact-only boot | same | yes (declared) |
| `packages/cli/src/utils/schema-migrate.ts:303` (`bootSchemaStack`) |
the one-shot funnel for 13 `os migrate *` / `os meta *` commands | same
| yes (declared), see below |
| runtime and cli tests and fixtures | memory or sqlite files | same |
yes (declared) |

No caller has a proxied or non-local `sys_metadata`, so the stop valve
does not fire.

Outside this repository:
- An org-wide code search for `createStandaloneStack` returns only
`objectstack-ai/duly`: tests and seed scripts of an ordinary standalone
app on its own database.
- `objectstack-ai/cloud` is **NOT MEASURED**. Control leg: the same
search for `hydrateMetadataFromDb` returns 0 hits outside this
repository, although the plugin's own docblock says the cloud single-env
tenant runtime sets that option. So the search cannot see that
repository.
- Either way, both caution clauses hold inside the function, so an
unmeasured embedder gets the same composition.

## Why `bootSchemaStack` hydrates too

Ruling ① lets a read-only one-shot boot turn hydration off "if it
genuinely does not need it". Measured, the one-shots need it, or are
neutral:

- **`os migrate plan`:** its unmanaged-table sweep
(`packages/cli/src/utils/unmanaged-tables.ts` header) says the question
"is only answerable when the composed object set actually MIRRORS what
this deployment's `os serve` boot registers". After this PR, `os serve`
registers runtime-authored objects.
- **`os migrate files-to-references`:** it refuses an empty scan because
"this command's verdict is what later authorises irreversible
behaviour". Without hydration it would silently skip the file fields of
runtime-authored objects.
- **The read writes nothing:** `loadMetaFromDb` is `engine.find` plus
registry registration plus log lines. A boot that defers DDL still
defers the Phase-3 tables of what it hydrated.
- **Measured at `c945f282`:** `duplicates.integration.test.ts` (boot
included, database byte-identical after the run),
`platform-migrations-arming.integration.test.ts` and the six
`schema-migrate*` / `unmanaged-tables` integration suites all pass. The
stack's construction is the same `true` at the current head.

## Ruling ④: the false log line

"Project kernel — skipping sys_metadata hydration" is now unreachable on
this stack. It sits only in the `else` of the gate above, and
`hydrateMetadataFromDb` is a literal `true` that no caller can change.
The new unit test pins the flag under every way an environment id is
stamped.

Observed directly:
- on the unfixed source, the unit test's two boots each printed that
line once;
- on the fix, the second boot prints `Metadata restored from database to
SchemaRegistry {"loaded":2,"errors":0,"invalid":0}` and no skip line.

No edit to `packages/objectql` was needed.

## Reach beyond one object (mechanism assumption 6)

`packages/runtime/src/standalone-stack-hydrate-metadata.test.ts` boots
the real stack twice on one SQLite file:
- **Boot 1** writes an env-wide `object` row **and** an env-wide `app`
row through the protocol, and inserts one record.
- **Boot 2** has both rows in the registry, and the record reads back
through the engine.

The `app` is not in the registry on the boot that wrote it. On this
composition, the protocol's write-through for non-object types returns
early on a kernel with an environment id (see Acceptance notes). So boot
hydration is the only thing that puts it there, which makes it a sharp
second leg.

Org-scoped rows are deliberately not asserted. `loadMetaFromDb` reads
`organization_id IS NULL` only (ADR-0005: per-org overlays are served on
demand).

Diagnostics hydration now surfaces at boot, reported and not suppressed.
`loadMetaFromDb` and its `reportUnhydratableOrgScopedRows` (objectstack-ai#6190) now
run on every standalone boot:
- a stored row that cannot register prints `[Protocol]
[metadata_field_type_refused] …` at `error`, or `[Protocol] Failed to
hydrate TYPE/NAME: …` / `[Protocol] [metadata_spec_invalid] …` at
`warn`;
- org-scoped rows of types that are not per-org overridable get one
aggregated line.

None of these fired in any suite run here. Against a real install's
`sys_metadata` they are NOT MEASURED; the changeset names these lines
for upgraders.

## The pin

`packages/cli/test/package-restart-acceptance.integration.test.ts`:
probe 2's `it.fails` is promoted to a plain `it`, and the file's header
now describes the fixed state.

A log-line assertion I added beside it was removed in this PR. The
ablation leg showed it stays green on the unfixed build, because `os
serve` does not print that INFO line at the pin's log level.

## Tests (head `46fd71b1`)

- **The pin:** `pnpm --filter @objectstack/cli exec vitest run --project
integration --maxWorkers=2
test/package-restart-acceptance.integration.test.ts` gives `Tests 5
passed (5)`. `ablation-dist-preflight` shows the runtime `dist` carries
the literal.
- **Unit test:** `pnpm --filter @objectstack/runtime exec vitest run
--maxWorkers=2 src/standalone-stack-hydrate-metadata.test.ts` gives
`Tests 2 passed (2)`.
- **Runtime suite:** `pnpm --filter @objectstack/runtime test` gives
`Test Files 279 passed (279)`, `Tests 3906 passed | 1 skipped (3907)`.
- **Typecheck:** `pnpm --filter @objectstack/runtime typecheck` exits 0,
with `check:test-typecheck: OK … 27 file(s) / 191 error(s) / 69 pinned
signature(s)` (ledger unchanged).
- **Lint:** full `pnpm lint` (`eslint . --no-inline-config`) exits 0.
- **Gates:** all 60 commands that `node scripts/pm/dispatch-gates.mjs
--commands` derives at `46fd71b1` exit 0. The `--ran` reconciliation
reads "60 derived, 60 run, 0 NOT-MEASURED, 0 UNRUN".
- **At `c945f282`**, before this revision:
- the CLI unit project: `Test Files 224 passed (224)`, `Tests 3158
passed (3158)`;
  - `pnpm --filter @objectstack/cli typecheck`: exit 0;
- CLI `--project integration` on 10 files (the pin, `duplicates`,
`meta.stored-flow-resolution`, `platform-migrations-arming`, the five
`schema-migrate*` files and `unmanaged-tables`): `Test Files 10 passed
(10)`, `Tests 38 passed (38)`.

This revision touches no CLI file, and the rest of the CLI integration
project is declared to CI.

**Ablation at `46fd71b1`, from committed state.** The mutation flipped
the literal's `true` to `false` through `node
scripts/ablation-replace.mjs`, anchored on the construction line.

- **Mutation landed:** anchor x1 to x0, blob `b10937d6` to `dc0eab77`,
and on-disk counts `true=0 false=1`.
- **Reached `dist`:** after rebuilding `@objectstack/runtime`,
`ablation-dist-preflight` reports the `true` spelling absent from all 6
dist files and the flipped spelling present in 2.
- **Unit test:** 2 failed. The restart row fails at "hydr_widget is
registered after the restart: expected undefined", the registry check
just before its data read.
- **Pin:** `1 failed | 4 passed`. Probe 2 fails with "GET
/data/leave_request after a restart: {"error":"Object 'leave_request' is
not registered","code":"OBJECT_NOT_FOUND"} … expected 404 to be 200".
- **Restore:**
  - blob `b10937d6` == HEAD, and `git status --porcelain` is empty;
- runtime rebuilt: the literal is present in 2 dist files and `false`
absent from all 6;
  - the unit test gives 2 passed and the pin 5 passed.

## Acceptance notes (observations, not filed)

- **Same deduction, non-object write-through:**
`packages/metadata-protocol/src/protocol.ts` `applyRegistryWriteThrough`
returns early for every non-object type when `this.environmentId !==
undefined`. That is the same deduction class, one package over. On a
standalone kernel, a runtime-saved `app` is absent from the registry on
the boot that wrote it, until a listing or the next boot hydrates it;
the new unit test's boot 1 measured this. No user-visible failure was
measured, so it is recorded here, not filed.
- **Comment drift:** `packages/objectql/src/plugin.ts` (the Phase-2
bridge comment) and `loadMetaFromDb`'s comment still call
`SchemaRegistry` a process-wide singleton, while `engine.ts:3054-3061`
says each engine now owns its own. Both files are read-only for this
lane.

## Relations

objectstack-ai#17676 remains open: that card belongs to the engine seat, and this PR
delivers the runtime half that its acceptance pin (PR objectstack-ai#20069) waits on.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01TnPAC1UsTGfHPXVUCL6iLn)_

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant